Software-driven design optimization for mapping between floating-point and fixed-point multiply accumulators

ABSTRACT

An example multiply accumulate (MACC) circuit includes a multiply-accumulator having an accumulator output register, a scaler, coupled to the multiply accumulator, and a control circuit coupled to the multiply-accumulator and the scaler. The control circuit is configured to provide control data to the scaler, the control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing a first right shift; a multiplier; and a second right shift.

TECHNICAL FIELD

Examples of the present disclosure generally relate to computing systems and electronic circuits and, in particular, to software-driven design optimization for mapping between floating-point and fixed-point multiply accumulators.

BACKGROUND

Machine learning is the science of inducing computing systems to act without being explicitly programmed. Classical machine learning includes various clustering and classification techniques, including K-means clustering, linear and logistic regressions, stochastic gradient decent, association rule learning, and the like. Deep learning is a newer frontier in machine learning. Deep learning is a class of machine learning algorithms that uses multiple layers of nonlinear processing units for feature extraction and transformation. Deep learning algorithms can be unsupervised (e.g., pattern analysis) or supervised (e.g., classification). The deep learning algorithm can be implemented using layers of an artificial neural network (ANN) (referred to herein as a “neural network”).

In general, a neural network is a collection of nodes (i.e., the “neurons”) that are connected in a graph. A node in a neural network computes a sum of weighted inputs and adds an optional bias to the sum. The output of the node is a function of the final sum (referred to as an “activation function”). Example activation functions include the sigmoid function, the hyperbolic tangent (tan h) function, the Rectified Linear Unit (ReLU) function, and the identity function. Neural network models are often organized into layers of nodes, which define a specific topology, and corresponding weights and biases. The weights and biases are referred to as network parameters.

In general, a neural network includes an input layer and an output layer and can optionally include one or more hidden layers between the input and output layers. A neural network used in deep learning applications typically includes many hidden layers, which gives rise to the term deep neural network (DNN). The layers of a neural network can be densely connected (e.g., each node in a layer is fully connected to all nodes in a previous layer) or sparsely connected (e.g., each node in a layer is connected to only a portion of the nodes in a previous layer). A convolutional neural network (CNN) is a type of DNN that includes one or more sparsely connected layers, referred to as convolutional layers. A CNN is well-suited for processing image or video data. Other types of DNNs include recurrent neural network (RNNs), which are well-suited for processing speech and text data.

Convolution operations can be performed using a number of techniques, which are typically limited by the ability to use a large number of digital signal processors (DSPs), the requirement of on-chip buffers, and/or the data access patterns. One example convolution technique creates a shift register of samples that are fed into a DSP array. This technique is limited in terms of not being able to use striding or dilated convolutions in which the convolution window skips columns and rows in the input image. This is due to a conflict between use of the shift registers to cycle through samples in sequence and the stride or dilation that skips or jumps samples in the input image. Accordingly, it is desirable to provide an improved architecture to compute parallel generalized convolutions.

SUMMARY

Techniques for software-driven design optimization for mapping between floating-point and fixed-point multiply accumulators are described. In an example, a multiply accumulate (MACC) circuit includes: a multiply-accumulator having an accumulator output register; a scaler, coupled to the multiply accumulator; and a control circuit coupled to the multiply-accumulator and the scaler, the control circuit configured to provide control data to the scaler, the control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing a first right shift; a multiplier; and a second right shift.

In another example, an integrated circuit (IC) includes: a memory controller configured to access a memory having image data and weight data stored therein; a processor including a plurality of multiply-accumulate (MACC) circuits configured to process the image data and the weight data, each of the MACC circuits including: a multiply-accumulator having an accumulator output register; a scaler, coupled to the multiply accumulator; and a control circuit coupled to the multiply-accumulator and the scaler, the control circuit configured to provide control data to the quantizer, the control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing a first right shift; a multiplier; and a second right shift.

In another example, a method of controlling a multiply-accumulate (MACC) circuit includes: determining control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing a first right shift; a multiplier; and a second right shift; and

loading the control data to the MACC circuit to configure a scaler coupled to the accumulator output register.

These and other aspects may be understood with reference to the following detailed description.

BRIEF DESCRIPTION OF THE DRAWINGS

So that the manner in which the above recited features can be understood in detail, a more particular description, briefly summarized above, may be had by reference to example implementations, some of which are illustrated in the appended drawings. It is to be noted, however, that the appended drawings illustrate only typical example implementations and are therefore not to be considered limiting of its scope.

FIG. 1 is a block diagram depicting a system for implementing neural networks according to an example.

FIG. 2 is a block diagram depicting a computing system according to an example.

FIG. 3 is a block diagram depicting an acceleration circuit according to an example.

FIG. 4 is a block diagram depicting a programmable integrated circuit (IC) according to an example.

FIG. 5 illustrates a field programmable gate array (FPGA) implementation of a programmable IC according to an example.

FIG. 6 is a block diagram depicting a multiply-accumulate (MACC) circuit according to an example.

FIG. 7 is a block diagram depicting a neural network according to an example.

FIG. 8 illustrates input image data, filter data, and output image data for a convolution operation according to an example.

FIG. 9 illustrates convolution in terms of a two-dimensional matrix multiplication operation.

FIG. 10 illustrates a pair of fixed-point integers according to an example.

FIG. 11 depicts a table that shows determined most-significant bit (MSB) and least-significant bit (LSB) values for different layers of a neural network according to an example.

FIG. 12 is a flow diagram depicting a method of determining MSB and LSB bit indices of accumulator output for layers of a neural network according to an example.

FIGS. 13A-B are block diagrams depicting a quantizer according to an example.

FIGS. 14A-B are block diagrams depicting a quantizer according to another example.

FIG. 15 is a block diagram depicting a quantizer according to yet another example.

FIG. 16 is a flow diagram depicting a method of operating a MACC circuit according to an example.

To facilitate understanding, identical reference numerals have been used, where possible, to designate identical elements that are common to the figures. It is contemplated that elements of one example may be beneficially incorporated in other examples.

DETAILED DESCRIPTION

Various features are described hereinafter with reference to the figures. It should be noted that the figures may or may not be drawn to scale and that the elements of similar structures or functions are represented by like reference numerals throughout the figures. It should be noted that the figures are only intended to facilitate the description of the features. They are not intended as an exhaustive description of the claimed invention or as a limitation on the scope of the claimed invention. In addition, an illustrated example need not have all the aspects or advantages shown. An aspect or an advantage described in conjunction with a particular example is not necessarily limited to that example and can be practiced in any other examples even if not so illustrated or if not so explicitly described.

Techniques for software-driven design optimization for mapping between floating-point and fixed-point multiply accumulators are described. The techniques provide for software-driven design optimization for mapping between floating-point multiply-accumulate units and fixed-point multiply-accumulate units. The techniques further provide a scaler circuit optimized for convolutional neural networks. The design methodology allows efficient time/resource utilization to implement accurate multiply-accumulate bit selection with fine grain control in a software driven flow. These and further aspects can be understood with reference to the description of the drawings below.

FIG. 1 is a block diagram depicting a system 100 for implementing neural networks according to an example. The system 100 includes a computer system 102 and one or more computer systems 108. The computer system 102 includes conventional computing components configured to execute software that provides one or more design tools 104. Each computer system 108 executes one or more neural networks 110. The neural network(s) 110 are implemented using applications 112, acceleration libraries 114, and one or more hardware accelerators 116.

In an example, the hardware accelerator(s) 116 include programmable integrated circuits (ICs), such as field programmable gate arrays (FPGAs). The acceleration libraries 114 provide application programming interfaces (APIs) to interface with the hardware accelerator(s) 116. The acceleration libraries 114 can also include libraries that provide neural network functions, including predefined and optimized implementations of neural network layers and other types of neural network structures. Thus, the neural network(s) 110 can include both hardware portions implemented in the hardware accelerator(s) 116, as well as software portions implemented in the acceleration libraries 114. The applications 112 invoke the APIs of the acceleration libraries 114 to program and control the hardware accelerator(s) 116 to implement the neural network(s) 116.

A designer interacts with the design tool(s) 104 to define the neural network(s) 110. The design tool(s) 104 can generate files for programming the hardware accelerator(s) 116 (e.g., configuration bitstreams for FPGAs), files that provide the acceleration libraries 114, and files that provide the applications 112. The designer can define the hardware portions of the neural network(s) 110 using a register transfer language (RTL) or using a programming language, such as C, C++, OpenCL, and the like, or a combination of RTL and programmable language(s). The user can define the software portions of the neural network(s) 110 using a programming language, such as C, C++, OpenCL, etc. The design tool(s) 104 compile the software-defined neural networks to generate files for programming the hardware accelerator(s) 116 and library files for the acceleration libraries 114. The designer can make use of libraries 106 that provide class libraries, template libraries, and the like to assist in developing the hardware and software portions of the neural network(s) 110.

A user can define the applications 112 using a programming language (e.g., C, C++, Python, etc.). The user can make use of neural network frameworks and libraries, such as Caffe, TensorFlow, MXNet, and the like.

FIG. 2 is a block diagram depicting a computing system 108 according to an example. The computing system 108 includes hardware 204 and software 206 executing on the hardware 204. The hardware 204 includes a processing system 210, system memory 1216, storage devices (“storage 218”), and a hardware accelerator 116. The software 206 includes an operating system (OS) 244, the acceleration libraries 114, and the applications 112.

The processing system 210 includes a microprocessor 212, support circuits 214, and a peripheral bus 215. The microprocessor 212 can be any type of general-purpose central processing unit (CPU), such as an ×86-based processor, ARM®-based processor, or the like. The microprocessor 212 can include one or more cores and associated circuitry (e.g., cache memories, memory management units (MMUs), interrupt controllers, etc.). The microprocessor 212 is configured to execute program code that perform one or more operations described herein and which can be stored in the system memory 216 and/or the storage 218. The support circuits 214 include various devices that cooperate with the microprocessor 212 to manage data flow between the microprocessor 212, the system memory 216, the storage 218, the hardware accelerator 116, or any other peripheral device. For example, the support circuits 214 can include a chipset (e.g., a north bridge, south bridge, platform host controller, etc.), voltage regulators, firmware (e.g., a BIOS), and the like. The support circuits 214 manage data flow between the microprocessor 212 and the peripheral bus 215, to which various peripherals, such as the hardware accelerator 116, are connected. In some examples, the microprocessor 212 can be a System-in-Package (SiP), System-on-Chip (SoC), or the like, which absorbs all or a substantial portion of the functionality of the chipset (e.g., north bridge, south bridge, etc.). The peripheral bus can implement an expansion bus standard, such as Peripheral Component Interconnect Express (PCIe). In the example, the processing system 210 is shown separate from the hardware accelerator 116. In other examples discussed further below, the processing system 210 and the hardware accelerator 116 can be implemented on the same integrated circuit (IC) using a System-On-Chip (SoC).

The system memory 216 is a device allowing information, such as executable instructions and data, to be stored and retrieved. The system memory 216 can include, for example, one or more random access memory (RAM) modules, such as double-data rate (DDR) dynamic RAM (DRAM). The storage device 218 includes local storage devices (e.g., one or more hard disks, flash memory modules, solid state disks, and optical disks) and/or a storage interface that enables the computing system 108 to communicate with one or more network data storage systems. The hardware 204 can include various other conventional devices and peripherals of a computing system, such as graphics cards, universal serial bus (USB) interfaces, and the like.

The hardware accelerator 116 includes a programmable IC 228, a non-volatile memory 224, and RAM 226. The programmable IC 228 can be an FPGA or the like or an SoC having an FPGA or the like. The NVM 224 can include any type of non-volatile memory, such as flash memory or the like. The RAM 226 can include DDR DRAM or the like. The programmable IC 228 is coupled to the NVM 224 and the RAM 226. The programmable IC 228 is also coupled to the peripheral bus 215 of the processing system 210.

The OS 244 can be any commodity operating system known in the art, such as such as Linux®, Microsoft Windows®, Mac OS®, or the like. The acceleration libraries 114 includes drivers and libraries that provide APIs for command and control of the hardware accelerator 116. The applications 112 include software executing on the microprocessor 212 that invokes the APIs of the acceleration libraries 114 to implement neural network(s).

In operation, the programmable IC 228 is configured with an acceleration circuit 230. The acceleration circuit 230 generally includes a base platform 230A and a kernel 230B. For example, the acceleration circuit 230 can be implemented using a static region 234 and a programmable region 236. The static region 234 includes support circuits 240 for providing an interface to the peripheral bus 215, the NVM 224, and the RAM 226. The programmable region 236 can include one or more kernel circuits (“kernel(s) 238”). The base platform 230A is implemented using the static region 234, and the kernel 230B is implemented using the programmable region 236. In another example, the base platform 230A can also be implemented using a portion of the programmable region 236. Thus, in some examples, the programmable region 236 also includes some interface circuits. In some examples, the acceleration circuit 230 can include more than one programmable region 236, each of which can be individually configured with kernel(s) 238.

The static region 234 is “static” in that the circuitry thereof remains constant across reconfigurations of the programmable region 236. In an example, the support circuits 240 include PCIe endpoint circuits, a direct memory access (DMA) controller, interconnects, a memory controller, a memory interface circuit (e.g., a DDR interface), decoupler circuits (to support partial reconfiguration), flash programmer, debug circuits, and the like. In some examples, the programmable region 236 does not include any of the support circuits 240. In other examples, some support circuits are implemented in the programmable region 236. In such case, the programmable region 236 can be referred to as an “expanded programmable region.” In either case, in one example, some support circuits 240 are always present in the static region 234, such as the PCIe circuits and the DMA circuits.

FIG. 3 is a block diagram depicting an acceleration circuit 230 according to an example. The acceleration circuit 230 includes the support circuits 240 and a kernel 238. In the example, the support circuits 240 include a PCIe endpoint circuit (“PCIe endpoint 302”), a PCIe DMA controller 304, interconnect circuits (“interconnect 306”), memory controllers 310, and memory interfaces 312. The support circuits 240 can include other circuits, which are omitted for clarity (e.g., decoupler circuits, debug circuits, etc.). The PCIe endpoint 302 provides a physical interface to the peripheral bus 215. The PCIe DMA controller 304 facilitates DMA operations to the RAM 226 and the kernel 238. The interconnect 306 couples the PCIe DMA controller 304 to the memory controllers 310 and to the kernel 238. The memory controllers 310 are coupled to the memory interfaces 312. The memory interfaces 312 are coupled to the RAM 226.

In operation, the acceleration libraries 246 can access the RAM 226 directly through the PCIe DMA controller 304. The acceleration libraries 246 can also access the kernel 238 through the PCIe DMA controller 304. The kernel 238 can access the RAM 226 through the memory controllers 310. Data can be exchanged between the software 206 and the kernel 238 using DMA operations between the system memory 216 and the RAM 226.

In the example, the kernel 238 uses interfaces 330, 331, and 332 to communicate with the interconnect 306. In particular, these interfaces include a first read interface 330, a second read interface 331, and a read/write interface 332. For example, the read interface 330 can be used as a control interface for controlling the kernel 238. The read interface 331 can be used to read from the RAM 226 through a first one of the memory interfaces 312. The read/write interface 332 can be used to read and write from the RAM 226 through a second one of the memory interfaces 312.

The kernel 238 includes an interconnect interface 304, control logic 342, and processing circuits 341. The processing circuits 341 include an IM2COL circuit (“IM2COL 344”), a read control circuit (“read control 346”), a multiplexer 356, first-in-first-out circuits (“FIFOs 358”), digital signal processor (DSP) array 362, a scaler circuit (“scaler 364”), a max pool circuit (“max pool 366”), a multiplexer 368, FIFOs 354, write control circuit (“write control 352”), a cache 348, a read control circuit (“read control 350”), and FIFOs 360. The interconnect interface 340 is coupled to the interfaces 330, 331, and 332, the control logic 342, and the processing circuits 341. The interconnect interface 340 can include switches, clock converters, and the like to facilitate communication between the control logic 342 and the interface 330, as well as between the processing circuits 341 and the interfaces 331 and 332.

In the example, the interconnect interface 340 is coupled to inputs of the IM2COL circuit 344, the read control circuit 346, the cache 348, and the write control circuit 352. Outputs of the IM2COL circuit 344 and the read control circuit 346 are coupled to inputs of the multiplexer 356. An output of the multiplexer 356 is coupled to an input of the FIFOs 358. An output of the FIFOs 358 is coupled to a first input of the DSP array 362. An output of the cache 348 is coupled to an input of the read control circuit 350. An output of the read control circuit 350 is coupled to an input of the FIFOs 360. An output of the FIFOs 360 is coupled to a second input of the DSP array 362. An output of the DSP array 362 is coupled to an input of the scaler 364. An output of the scaler 364 is coupled to an input of the max pool circuit 366 and an input of the multiplexer 368. An output of the max pool circuit 366 is coupled to another input of the multiplexer 368. An output of the multiplexer 368 is coupled to an input of the FIFOs 354. An output of the FIFOs 354 is coupled to the write control circuit 352.

In operation, the DSP array 362 performs matrix multiplication operations for implementing a neural network. The inputs of the DSP array 362 receive input activation matrices from the FIFOs 358 and weight matrices from the FIFOs 360. The input activation matrices can be read directly from the RAM 226 using the read control circuit 346. Alternatively, the input activations can be read from the RAM 226 and processed by the IM2COL circuit 344 for input to the DSP array 362. Embodiments of the IM2COL circuit 344 are described below. Weight matrices can be read from the RAM 226 by the read control circuit 350 and cached in cache 348. The scaler 364 can scale the output of the DSP array 362. The max pool circuit 366 can implement a max pooling function on the scaled output of the DSP array 362. In one example, the max pool circuit 966 is implemented using CLBs or other configurable logic. Either the output of the max pool circuit 366 or the scaler 364 can be stored in the FIFOs 354. The write control circuit 352 writes data in the FIFOs to the RAM 226. The control logic 342 controls the various circuits in the processing circuits 341, such as the IM2COL circuit 344, the read control circuit 346, the multiplexers 356 and 368, the read control circuit 350, and the scaler 364, the max pool circuit 366, and the write control circuit 352.

FIG. 4 is a block diagram depicting a programmable IC 228 according to an example. The programmable IC 228 includes programmable logic 3, configuration logic 25, and configuration memory 26. The programmable IC 228 can be coupled to external circuits, such as the NVM 224, the RAM 226, and other circuits 29. The programmable logic 3 includes logic cells 30, support circuits 31, and programmable interconnect 32. The logic cells 30 include circuits that can be configured to implement general logic functions of a plurality of inputs. The support circuits 31 include dedicated circuits, such as transceivers, input/output blocks, digital signal processors, memories, and the like. The logic cells and the support circuits 31 can be interconnected using the programmable interconnect 32. Information for programming the logic cells 30, for setting parameters of the support circuits 31, and for programming the programmable interconnect 32 is stored in the configuration memory 26 by the configuration logic 25. The configuration logic 25 can obtain the configuration data from the nonvolatile memory 224 or any other source (e.g., the DRAM 28 or from the other circuits 29). In some examples, the programmable IC 228 includes a processing system 2. The processing system 2 can include microprocessor(s), memory, support circuits, 10 circuits, and the like. For example, the processing system 2 can include circuits similar to the processing system 210. In some examples, the processing system 2 can be used in place of the processing system 210. In such case, the entire computing system 108 can be implemented using the programmable IC 228, where the software 206 executes on the processing system 2.

FIG. 5 illustrates an FPGA implementation of the programmable IC 228 that includes a large number of different programmable tiles including transceivers 37, configurable logic blocks (“CLBs”) 33, random access memory blocks (“BRAMs”) 34, input/output blocks (“IOBs”) 36, configuration and clocking logic (“CONFIG/CLOCKS”) 42, digital signal processing blocks (“DSPs”) 35, specialized input/output blocks (“I/O”) 41 (e.g., configuration ports and clock ports), and other programmable logic 39 such as digital clock managers, analog-to-digital converters, system monitoring logic, and so forth. The FPGA can also include PCIe interfaces 40, analog-to-digital converters (ADC) 38, and the like.

In some FPGAs, each programmable tile can include at least one programmable interconnect element (“INT”) 43 having connections to input and output terminals 48 of a programmable logic element within the same tile, as shown by examples included at the top of FIG. 5. Each programmable interconnect element 43 can also include connections to interconnect segments 49 of adjacent programmable interconnect element(s) in the same tile or other tile(s). Each programmable interconnect element 43 can also include connections to interconnect segments 50 of general routing resources between logic blocks (not shown). The general routing resources can include routing channels between logic blocks (not shown) comprising tracks of interconnect segments (e.g., interconnect segments 50) and switch blocks (not shown) for connecting interconnect segments. The interconnect segments of the general routing resources (e.g., interconnect segments 50) can span one or more logic blocks. The programmable interconnect elements 43 taken together with the general routing resources implement a programmable interconnect structure (“programmable interconnect”) for the illustrated FPGA.

In an example implementation, a CLB 33 can include a configurable logic element (“CLE”) 44 that can be programmed to implement user logic plus a single programmable interconnect element (“INT”) 43. A BRAM 34 can include a BRAM logic element (“BRL”) 45 in addition to one or more programmable interconnect elements. Typically, the number of interconnect elements included in a tile depends on the height of the tile. In the pictured example, a BRAM tile has the same height as five CLBs, but other numbers (e.g., four) can also be used. A DSP tile 35 can include a DSP logic element (“DSPL”) 46 in addition to an appropriate number of programmable interconnect elements. An 10B 36 can include, for example, two instances of an input/output logic element (“IOL”) 47 in addition to one instance of the programmable interconnect element 43. As will be clear to those of skill in the art, the actual I/O pads connected, for example, to the I/O logic element 47 typically are not confined to the area of the input/output logic element 47.

In the pictured example, a horizontal area near the center of the die (shown in FIG. 8) is used for configuration, clock, and other control logic. Vertical columns 51 extending from this horizontal area or column are used to distribute the clocks and configuration signals across the breadth of the FPGA.

Some FPGAs utilizing the architecture illustrated in FIG. 5 include additional logic blocks that disrupt the regular columnar structure making up a large part of the FPGA. The additional logic blocks can be programmable blocks and/or dedicated logic.

Note that FIG. 5 is intended to illustrate only an exemplary FPGA architecture. For example, the numbers of logic blocks in a row, the relative width of the rows, the number and order of rows, the types of logic blocks included in the rows, the relative sizes of the logic blocks, and the interconnect/logic implementations included at the top of FIG. 5 are purely exemplary. For example, in an actual FPGA more than one adjacent row of CLBs is typically included wherever the CLBs appear, to facilitate the efficient implementation of user logic, but the number of adjacent CLB rows varies with the overall size of the FPGA.

Software-Driven Design Optimization for Mapping Between Floating-Point and Fixed-Point Multiply Accumulators

FIG. 6 is a block diagram depicting a multiply-accumulate (MACC) circuit 600 according to an example. The MACC circuit 600 can be used as a computation element in the DSP array 362. The DSP array 362 can include any number of instances of the MACC circuit 600.

The MACC circuit 600 includes a multiply-accumulator 602, a scaler 616, and a control circuit 604. The multiply-accumulator 602 includes three inputs designated A, B, and C. The A input has a width of M, the B input has a width of N, and the C input has a width of P, where M, N, and P are positive integers. The multiply-accumulator 602 includes an output having a width of P coupled to an input of the scaler 616. The scaler 616 has an output having a width of Q, where Q is a positive integer. Outputs of the control circuit 604 are coupled to control inputs of the multiply-accumulator 602 and the scaler 616. An input of the control circuit 604 receives an instruction for configuring the multiply-accumulator 602 and the scaler 616.

In the example, the multiply-accumulator 602 includes registers 606A . . . 606C, a multiplier 608, a multiplexer 610, an adder 612, and a register 614. Inputs of the registers 606A . . . 606C are respectively coupled to the A, B, and C inputs of the multiply-accumulator 602. Outputs of the registers 606A and 606B are coupled to inputs of the multiplier 608. An output of the multiplier 608, having a width M+N, is coupled to an input of the adder 612. An output of the adder 612, having a width of P, is coupled to a register 614. An output of the register 614 provides the output of the multiply-accumulator 602. An output of the register 606C is coupled to one input of the multiplexer 610. The output of the register 614 is coupled to another input of the multiplexer 610. An output of the multiplexer 610 is coupled to another input of the adder 612. A control input of the multiplexer 610 receives a control signal (Mux Ctrl.) from the control circuit 604.

In operation, the multiplier 608 performs multiplications of A and B. When the multiplexer 610 selects the output of the register 614, the adder 612 operates as an accumulator to accumulate the output of the multiplier 608. Otherwise, the adder 612 performs a sum of A×B and C. The register 614 stores the output of the adder 612. The scaler 616 reduces the resolution of the P-bit output of the multiply-accumulator 602 to a Q-bit output (e.g., Q<P). For example, P can be 48 bits and Q can be 8 bits or 16 bits. Operation of the scaler 616 is discussed further below. The control circuit 604 is configured to provide control data to the scaler 616. The control data includes data indicative of a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the register 614.

FIG. 7 is a block diagram depicting a neural network 700 according to an example. The neural network 700 includes a plurality of layers 702, e.g., layers 702 ₁ . . . 702 _(N), where N is an integer greater than zero. Each layer 702 has an input and an output. The layer 702 ₁ has an input 704 ₁ and an output 704 ₂. The input to the layer 702 ₂ is the output 704 ₂ of the layer 702 ₁. The layer 702 ₂ includes an output 704 ₃. An output of a layer 702 _(N−1) (not shown) is the input of the layer 702 _(N). The layer 702 _(N) includes an output 704 _(N+1). Thus, the input of the neural network 700 is the input 704 ₁ and the output of the neural network is the layer 702 _(N+1). In an example, one or more of the layers 702 is a convolutional layer. Each convolutional layer can include further post-processing (not shown) of its output, such as ReLU, max pooling, scaling, or the like. The convolution operations for a convolutional layer are implemented by the processor 606. The input to a convolutional layer is formatted by the IM2COL circuit.

FIG. 8 illustrates input image data 802, filter data 804, and output image data 806 for a convolution operation according to an example. The convolution operation can be performed for a particular layer of a CNN, for example. The input image data 802 includes two-dimensional images, each having a width (IW) and a height (IH), for each of a number of channels (ID). Thus, the input image data 802 comprises an IW×IH×ID volume of image samples. For example, the input image data 802 can include 227×277 images in each of red, green, and blue (RGB) channels (e.g., 227×227×3). In another example, an inner convolutional layer of a CNN can include input image data with dimensions 55×55×96 (e.g., 96 channels each having a 55×55 image). Each image 808 can be represented by a two-dimensional matrix A=(a_(ij))_(IH×IW). Each image 808 includes an IH number of rows 814. The IM2COL circuit processes an image 808 on a row-by-row basis.

In some cases, each image 808 can be padded with columns of zero-value samples on the left and right edges and/or rows of zero-value samples on the top and bottom edges. Padding is represented by numbers PH and PW, where PH is padding height and PW is padding width. For example, PH=PW=0 is no padding; PH=PW=1 means a ring of zero-value samples surrounds the image samples; PH=1 means that one row of zero-value samples is added to the top edge and another row of zero-value samples is added to the bottom edge; and PW=2 means that two columns of zero-value samples are added to the right edge and another two columns of zero-value samples are added to the left edge.

The filter data 804 includes three-dimensional filters 804 ₁ . . . 804 _(OD), each having a width (FW), a height (FH), and the depth (ID). The terms “filter” and “kernel” are used interchangeably herein. Each three-dimensional filter 804 ₁ . . . 804 _(OD) is convolved with the input image data 802 to generate a respective channel of the output image data 806. Thus, the number of three-dimensional filters 804 ₁ . . . 804 _(OD) equals the depth (OD) of the output image. Also, the depth of each three-dimensional filter 804 ₁ . . . 804 _(OD) matches the depth (ID) of the input image data 802. For example, a convolutional layer of a CNN can include 96 three-dimensional filters having dimensions of 11×11×3. Each two-dimensional cross-section of a filter 804 ₁ . . . 804 _(OD) can be represented by a two-dimensional matrix B=(b_(ij))_(FH×FW).

The output image data 806 includes two-dimensional images, each having a width (OW) and a height (IH), for a number (OD) of channels. Thus, the output image data 806 forms an OW×OH×OD volume. For example, the output image data 806 can include 96 channels each having a 55×55 image. Each image 816 can be represented by a two-dimensional matrix C=(c_(ij))_(OH×OW). Each image 816 includes an OH number of rows.

The values of OH and OW depend on the filter dimensions (FH, FW), input image padding (PH, PW), horizontal stride (S_(h)), vertical stride (S_(v)), horizontal dilation (D_(h)), and vertical dilation (D_(v)). Notably,

${O\; H} = {\left\lfloor \frac{{I\; H} + {{2 \cdot P}\; H} - \left( {{\left( {D_{v} + 1} \right) \cdot \left( {{F\; H} - 1} \right)} + 1} \right)}{S_{v}} \right\rfloor + {1\mspace{14mu}{and}}}$ ${O\; W} = {\left\lfloor \frac{{I\; W} + {{2 \cdot P}\; W} - \left( {{\left( {D_{h} - 1} \right) \cdot \left( {{F\; W} - 1} \right)} + 1} \right)}{S_{h}} \right\rfloor + 1.}$ To ensure that the entire image is processed, the expression (IH+2PH−((Dv+1)(FH−1)+1)) should evaluate to be a multiple of S_(v) and the expression (IW+2PW−((D_(h)+1)(FW−1)+1)) should evaluate to be a multiple of Sh.

An output sample in an output image 812 depends on a neighborhood of input samples in each input image 808 referred to herein as a “receptive field.” Each receptive field includes FH×FW input samples. A given output sample c_(ij) in the output image 812 is computed by taking the dot product between vector of its receptive fields and a vector of given filter. Thus, the receptive fields of a given output sample c_(ij) include a volume of input samples equal to ID×FH×FW samples. The size of the receptive fields depends on the filter dimensions (FH, FW). The input samples of the receptive fields and the extent to which the receptive fields overlap one another depend on the stride and dilation parameters of the convolution and the padding of the input image data.

FIG. 9 illustrates convolution in terms of a two-dimensional matrix multiplication operation. A filter matrix 906 has an OD number of rows and an (ID×FH×FW) number of columns. In the filter matrix 906, each of the filters 804 ₁ . . . 804 _(OD) is converted into a vector having an (ID×FH×FW) number of elements. Each “vectorized” filter becomes a row 908 of the filter matrix 906.

An output image matrix 906 has an OD number of rows and an (OH×OW) number of columns. Each row 912 of the output image matrix 906 is a vectorized form of an output image 812. The output image matrix 906 includes an OD number of rows representing an OD number of channels of the output image data 806.

An input image matrix 904 has ID×FH×FW number of rows and OH×OW number of columns. The input image matrix 904 is formed so that each column 910 includes the receptive fields for a given output sample. Thus, the input image matrix 904 depends on filter size (FH, FW) and padding (PH, PW), as well as stride and dilation selected for the convolution.

In one technique, a processor can perform convolution by generating the matrices 902, 904, and 906 and performing the matrix multiplication operation. However, such a technique requires generation of the large input image matrix 904 using an image-to-column (IM2COL) process. The input image matrix 904 includes redundant data (e.g., image samples are repeated across the columns according to a particular pattern according to the defined overlap of receptive fields). For example, consider an input image data having 227×227×3 image samples (e.g., RGB image having height and width of 227 pixels each without padding). Assume further an 11×11×3 filter and a stride of four. In such an example, the input image data 802 includes 154,587 image samples, but the input image matrix 904 includes 1,098,075 image samples. If each image sample is one byte, generation of the input image matrix 904 requires approximately 1 MB of temporary storage. Of course, larger input sample sizes require even more temporary storage. Furthermore, computation of the input image matrix 904 requires complete traversal of the input image data 802 prior to performing the convolution operation.

As illustrated in FIGS. 8-9, the multiply-accumulate operations found in convolutional neural networks are of the form z=xy+z. When implemented using fixed-point arithmetic, x, y, and z can be quantized based on a bit width (bw) and a floating-point threshold (th). That is, a two's complement base-2 little endian integer b_(bw-1), . . . , b₁, b₀ represents the value:

$\left( {{{- b_{{bw} - 1}}2^{{bw} - 1}} + {\sum\limits_{i = 0}^{{bw} - 2}{b_{i}2^{i}}}} \right)\frac{t\; h}{2^{{bw} - 1} - 1}$ In other words, the two's complement base-2 little endian integer b_(bw-1), . . . , b₁, b₀ is obtained from a floating-point value by clamping (or saturating) the floating-point value to a strictly symmetric threshold range [−th, th], linearly scaling the result by a fixed-point scaling factor, and rounding the scaled result. In some cases, the strictly symmetric threshold range can be replaced by a nearly symmetric threshold range:

$\left\lbrack {{{- t}\;{h\left( \frac{2^{{bw} - 1}}{2^{{bw} - 1} - 1} \right)}},{t\; h}} \right\rbrack$ chosen as a function of some statistical analysis, such as min/max, standard deviation, or a measure such as the Kullback-Leibler divergence. The fixed-point scaling factor can be defined as:

${s\; f} = \frac{2^{{bw} - 1} - 1}{t\; h}$

FIG. 10 illustrates a pair of fixed-point integers according to an example. Each integer 1002 and 1004 includes a most-significant bit (MSB) that represents the sign of the integer. The integer 1002 is positive and the integer 1004 is negative. The least significant bits (LSBs) are used to represent the magnitude of the integer using an integer part and a fractional part. The integer part includes a mantissa and the fractional part includes zero or more fractional digits. For example, if there are zero fractional digits, the integer 1002 has the value 109. However, in the example where there are two fractional digits, the integer 1002 has the value 27.25. If there are zero fractional digits, the integer 1004 has the value −101. However, in the example where there are two fractional digits, the integer 1004 has the value −26.75. Note that the integers 1002 and 1004 can be interpreted to have different values depending on the hyper-parameter th. However, to the multiply-accumulator 602, the integers 1002 and 1004 are processed in the same manner regardless of the value of th. That is, the multiply-accumulator 602 functions the same regardless of the value of th.

If multiplier x and multiplicand y are given bit widths x_bw and y_bw, respectively, then the then the minimum (pre-rounding) accumulator bit width for their product is acc_bw=x_bw+y_bw. A larger bit width can be selected to prevent potential overflow or the accumulator can be clamped in the case of overflow. Similarly, the accumulator floating-point threshold is acc_th=x_th*y_th. Finally, provided the desired product bit width z_bw and floating-point threshold z_th, the accumulator output must be multiplied by the floating-point value:

$\frac{acc\_ sf}{z\_ sf} = \frac{{x\_ sf}*{y\_ sf}}{z\_ sf}$ which is then rounded and finally bits [b_(z_bw-1), b₀] are selected as the output.

Convolutional neural networks have the property that the floating-point value acc_sf/z_sf is less than or equal to one. Thus, in examples described herein, the floating-point multiplication can be replaced with an integer pre-scale right shift, scale, and post-scale right shift, with optional rounding stages immediately following each of the right shift operations. To obtain parameters for these three integer operations, the floating-point multiplier can be factored as follows:

$\frac{acc\_ sf}{z\_ sf} = {2^{- {\lfloor{\log_{2}{(\frac{z\_ sf}{acc\_ sf})}}\rfloor}}\left( {\frac{acc\_ sf}{z\_ sf}2^{{\lfloor{\log_{2}{(\frac{z\_ sf}{acc\_ sf})}}\rfloor} + {z\_ bw} - 1}} \right)2^{- {({z_{bw} - 1})}}}$ Thus, the accumulator output is first right shifted by:

${{rshift}\; 1} = \left\lfloor {\log_{2}\left( \frac{z_{sf}}{{acc}_{sf}} \right)} \right\rfloor$ including optional rounding. The result of the first right shift operation is then multiplied by:

${mul} = {{round}\left( {\frac{acc\_ sf}{z\_ sf}2^{{\lfloor{\log_{2}{(\frac{z\_ sf}{acc\_ sf})}}\rfloor} + {z\_ bw} - 1}} \right)}$ Finally, the result of the multiplication is right shifted by rshift2=z_bw−1 including optional rounding. In this form, mul is in the integer range of [1, 2^(z_bw-1)]. One example of an optional rounding operation is to right shift by the value rshift-1, add one, and then right shift by one. Furthermore, this method allows every convolution and inner product layer to have a single or a per output channel threshold and scaling factor for the weights, but the parameters rshift1, mul, and rshift2 can be selected such that all the outputs of the layer share the same threshold and scaling factor.

In some cases, acc_sf/z_sf can be zero or acc_sf/z_sf can be greater than one. In such case, the mul, rshift1, and rshift2 can be set as follows:

if acc_sf/z_sf==0:

-   -   rshift1=0     -   mul=0     -   rshift2=0         elif acc_sf/z_sf<1:     -   rshift1=np.floor(−np.log 2(acc_sf/z_sf)).astype(int)     -   mul=np.round(acc_sf/z_sf*pow(2, rshift1+z_bw−1)).astype(int)     -   rshift2=z_bw−1         elif acc_sf/z_sf==1:     -   rshift1=0     -   mul=1     -   rshift2=0         elif acc_sf/z_sf>1:     -   rshift1=0     -   mul=np.round(acc_sf/z_sf*pow(2, z_bw−1−np.ceil(np.log         2(acc_sf/z_sf)))).astype(int)     -   rshift2=(z_bw−1−np.ceil(np.log 2(acc_sf/z_sf))).astype(int)

Provided a quantization for a target CNN, software can analyze the accumulator bit widths and floating-point threshold for each layer to determine the MSB and LSB of accumulator output that needs to be selected to achieve the first right shift operation. FIG. 11 depicts a table 1100 that shows determined rshift1, mul, and rshift2 values for different layers of a CNN according to an example. The table 1100 shows values for five layers of a given CNN. Each layer is defined by an image sample bit width (x_bw), an image sample threshold (x_th), an image sample scale factor (x_sf), a weight sample bit width (y_bw), a weight sample threshold (y_th), a weight sample scale factor (y_sf), an output sample bit width (z_bw), an output sample threshold (z_th), an otuput sample scale factor (z_sf), and an accumulator-to-output sample multiplier (acc-to-z mult). The table 1100 also shows the values of rshift1, mul, and rshift2 for each layer. For layers 1, 2 and 4, rshift1 is 9; for layer 3, rshift1 is 8; and for layer 5 rshift1 is 10. The value of rshift2 is 7 for each layer 1 through 5. It can be seen from the table 1100, there are three unique values of rshift1. Thus, there are only three bit indices from which the LSB (and MSB) are selected from the accumulator to achieve the rshift1 operation. The scaler 616 is then configured to achieve the mul and rshift2 operations after selecting the appropriate bits from the accumulator.

FIG. 12 is a flow diagram depicting a method 1200 of determining MSB and LSB bit indices of accumulator output for layers of a CNN according to an example. The method 1200 can be performed by the design tool(s) 104 executing in the computer 104 or by software executing in the computer system(s) 108 (e.g., applications 112, acceleration libraries 114, etc.).

The method 1200 begins at step 1202, where the software selects bit widths, thresholds, and scale factors for the image samples, the weight samples, and the outputs. For example, each layer of a CNN can have the same or different values for these parameters (e.g., as shown in the table 1100). At step 1204, the software selects an accumulator-to-output multiplier (e.g., a value for acc_sf/z_sf). At step 1206, the software determines values for rshift1, mul, and rshift2. For example, the software can calculate the values using the equations described above. At step 1208, the software determines the MSB and LSB indices in the accumulator output to achieve the first right shift.

As described above, the scaler 616 needs to select a number of bits from the accumulator output between two bit indices. In an example, the accumulator output has a bit width of 16 from which the scaler 616 selects 8 bits. In such case, the scaler 616 can include eight 16:1 multiplexers to select among the bit indices for the MSB and LSB. However, as noted above, only a certain number of LSB (and MSB) bit indices are selected for the layers of a given CNN (e.g., three different LSB bit indices in the example table 1100 for implementing rshift1). Thus, in an example, the scaler 616 can be optimized to use just eight 3:1 multiplexers, since several of the bit indices in the accumulator output are never selected. In another example, the scaler 616 can be implemented using a shift register that shifts the accumulator output by a given amount to select the output bits. Without optimization, the scaler 616 would waste cycles shifting right by one bit per clock cycle before reaching the desired LSB. In an example, the scaler 616 can be optimized by immediately bypassing some of the bits that cannot be the LSB. Thus, the scaler 616 can be customized based on the target CNN, which conserves processing time and resources. Moreover, in an example, the complexity of the scaler 616 can be further reduced by manipulating the chosen bit widths and fractional lengths of the multiplier x, the multiplicand y, and the product z for each layer during training so that the desired LSB distribution condenses, potentially to a single bit index for all layers to implement rshift1. In such case, this eliminates the need for the scaler 616 to have any multiplexers or use any clock cycles to shift to the desired LSB.

FIG. 13A is a block diagram depicting the scaler 616 according to an example. The scaler 616 includes a connection network 1302, multiplexers 1304, a scaler register 1306, a multiplier 1310, and a right shifter 1314. The scaler 616 can also include optional rounding circuit 1308 and/or optional rounding circuit 1312. The connection network 1302 connects the bits of the accumulator output register 614 to inputs of the multiplexers 1304 based on the analysis performed by the method 1200. Outputs of the multiplexers 1304 are coupled to the scaler register 1306. The output of the scaler register 1306 is processed by the multiplier 1310 to perform the multiplication by mul and the right shifter 1314 to perform rshift2. The output of the scaler register 1306 is optionally rounded by rounding circuit 1308. The output of the multiplier 1310 is optional rounded by the rounding circuit 1312.

FIG. 13B is a block diagram depicting connection to the bit c7 of the scaler register 1306 according to an example where the scaler register 1306 has eight bits. According to the table 1100, in this particular target CNN, the possible MSB values are selected from b9, b8, and b7, of the accumulator output register 614 to implement right shifts of 8, 9, and 10, respectively. Thus, a multiplexer 1304 ₁ includes three inputs and selects among those bit indices to provide the value of C7. Other bit indices of the scaler register 1306 are loaded similarly. In the example, for eight bits of the scaler register 1306, the multiplexers 1304 include eight 3-input multiplexers. The connection network 1302 is configured to connect the appropriate bit indices of the accumulator output register 614 to the inputs of each multiplexer 1304 to load the appropriate bit index of the scaler register 1306.

FIG. 14A is a block diagram depicting the scaler 616 according to another example. The scaler 616 in the present example includes a shift register 1402 in place of the multiplexers 1304. FIG. 14B is a block diagram depicting connections between the accumulator output register 614, the shift register 1402, and the scaler register 1306. The connection network 1302 connects bit indices b9 . . . b0 of the accumulator output register 614 to bit indices d9 . . . d0 of the shift register 1402. Notably, the connection network 1302 does not include connections between bit indices b17 . . . b10, since those bit indices are not potential MSBs (according to the example table 1100). The bit indices d8 . . . d0 of the shift register 1402 are coupled to the bit indices c7 . . . c0 and r of the scaler register 1306. In this example, the bit index designated “r” is an extra bit used to store a remainder value (e.g., the scaler register 1306 has a bitwidth of nine).

FIG. 15 is a block diagram depicting the scaler 616 according to another example. In the present example, the scaler 616 includes control logic 1502, a multiplexer 1504, and a scaler shift register 1506. Inputs of the multiplexer 1504 are coupled to outputs of the accumulator output register 614. In an example, the multiplexer 1504 is coupled to only a portion of the outputs of the accumulator output register 614 (e.g., those bit indices that are never used in the scaled output can be omitted from being connected to the multiplexer 1504). An output of the multiplexer 1504 is coupled to a shift input of the scaler shift register 1506. An output of the control logic 1502 is coupled to a control input of the multiplexer 1504. The scaler shift register 1506 can include a parallel output to be processed by the rounding, multiplication, and right shifting operations described above in FIGS. 13A and 14A.

In operation, the control logic 1502 receives control data indicating the range of MSB to LSB to be selected from the accumulator output register 614. The control logic 1502 controls the multiplexer to select the bit indices of the accumulator output register 614 from MSB to LSB (or from LSB to MSB) to serially load the scaler shift register 1506. The scaler shift register 1506 then outputs the data through the parallel output.

FIG. 16 is a flow diagram depicting a method 1600 of operating the MACC circuit 600 according to an example. The method 1600 begins at step 1604, where the MSB to LSB range for each layer is determined. For example, software can execute the method 1200 described above to determine rshift1, mul, and rshift2 for each of the CNN layers. At step 1606, control data indicative of rshift1, mul, and rshif2 is loaded to the scaler circuit 616. At optional step 1602, software can train the CNN to condense the LSB distribution. As described above, the complexity of the scaler 616 can be further reduced by manipulating the chosen bit widths, thresholds, and scale factors of the multiplier x, the multiplicand y, and the product z for each layer during training so that the desired LSB distribution condenses, potentially to a single value for rshift1. In such case, this eliminates the need for the scaler 616 to have any multiplexers or use any clock cycles to shift to the desired LSB.

While the foregoing is directed to specific examples, other and further examples may be devised without departing from the basic scope thereof, and the scope thereof is determined by the claims that follow. 

What is claimed is:
 1. A multiply accumulate (MACC) circuit, comprising: a multiply-accumulator having an accumulator output register; a scaler, coupled to the multiply-accumulator; and a control circuit coupled to the multiply-accumulator and the scaler, the control circuit configured to provide control data to the scaler, the control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing, by the scaler, each of: a first right shift of an accumulator output, a multiplication of the first right shift result, and a second right shift of the result of the multiplication.
 2. The MACC circuit of claim 1, wherein the scaler comprises: a plurality of multiplexers; a connection network configured to couple a portion of the bit indices of the accumulator output register to the plurality of multiplexers; and a scaler register coupled to outputs of the plurality of multiplexers.
 3. The MACC circuit of claim 2, wherein each of the plurality of multiplexers comprises a plurality of inputs, and wherein the plurality of inputs of each of the plurality of multiplexers is coupled to a respective plurality of the bit indices of the accumulator output register.
 4. The MACC circuit of claim 1, wherein the scaler comprises: a shift register; a connection network configured to couple a portion of the bit indices of the accumulator output register to a plurality of bit indices of the shift register; and a scaler register coupled to the plurality of bit indices of the shift register.
 5. The MACC circuit of claim 1, wherein the scaler comprises: a multiplexer coupled to a portion of the bit indices of the accumulator output register; a scaler shift register coupled to an output of the multiplexer; and control logic coupled to a control input of the multiplexer.
 6. The MACC circuit of claim 5, wherein the control logic is configured to control the multiplexer based on the most-significant bit (MSB) to least significant bit (LSB) range.
 7. An integrated circuit (IC), comprising: a memory controller configured to access a memory having image data and weight data stored therein; a processor including a plurality of multiply-accumulate (MACC) circuits configured to process the image data and the weight data, each of the MACC circuits including: a multiply-accumulator having an accumulator output register; a scaler, coupled to the multiply-accumulator; and a control circuit coupled to the multiply-accumulator and the scaler, the control circuit configured to provide control data to the scaler, the control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from the accumulator output register for implementing, by the scaler, each of: a first right shift of an accumulator output, a multiplication of the first right shift result, and a second right shift of the result of the multiplication.
 8. The IC of claim 7, wherein the scaler comprises: a plurality of multiplexers; a connection network configured to couple a portion of the bit indices of the accumulator output register to the plurality of multiplexers; and a scaler register coupled to outputs of the plurality of multiplexers.
 9. The IC of claim 8, wherein each of the plurality of multiplexers comprises a plurality of inputs, and wherein the plurality of inputs of each of the plurality of multiplexers is coupled to a respective plurality of the bit indices of the accumulator output register.
 10. The IC of claim 7, wherein the scaler comprises: a shift register; a connection network configured to couple a portion of the bit indices of the accumulator output register to a plurality of bit indices of the shift register; and a scaler register coupled to the plurality of bit indices of the shift register.
 11. The IC of claim 7, wherein the scaler comprises: a multiplexer coupled to a portion of the bit indices of the accumulator output register; a scaler shift register coupled to an output of the multiplexer; and control logic coupled to a control input of the multiplexer.
 12. The IC of claim 11, wherein the control logic is configured to control the multiplexer based on the most-significant bit (MSB) to least significant bit (LSB) range.
 13. The IC of claim 7, further comprising programmable logic, wherein the scaler and the control logic are configured in the programmable logic.
 14. A method of controlling a multiply-accumulate (MACC) circuit, comprising: determining control data indicative of: a most-significant bit (MSB) to least significant bit (LSB) range for selecting bit indices from an accumulator output register, for implementing, by a scaler coupled to the accumulator output register, each of: a first right shift of an accumulator output, a multiplication of the first right shift result, and a second right shift of the result of the multiplication; and loading the control data to the MACC circuit to configure a scaler coupled to the accumulator output register.
 15. The method of claim 14, wherein determining control data comprises: selecting bit widths, thresholds, and scale factors of image samples, weight samples, and outputs in a convolutional neural network (CNN); determining the one or more MSB to LSB ranges to implement the first right shift.
 16. The method of claim 14, wherein the scaler comprises: a plurality of multiplexers; a connection network configured to couple a portion of the bit indices of the accumulator output register to the plurality of multiplexers; and a scaler register coupled to outputs of the plurality of multiplexers.
 17. The method of claim 16, wherein each of the plurality of multiplexers comprises a plurality of inputs, and wherein the plurality of inputs of each of the plurality of multiplexers is coupled to a respective plurality of the bit indices of the accumulator output register.
 18. The method of claim 14, wherein the scaler comprises: a shift register; a connection network configured to couple a portion of the bit indices of the accumulator output register to a plurality of bit indices of the shift register; and a scaler register coupled to the plurality of bit indices of the shift register.
 19. The method of claim 14, wherein the scaler comprises: a multiplexer coupled to a portion of the bit indices of the accumulator output register; a scaler shift register coupled to an output of the multiplexer; and control logic coupled to a control input of the multiplexer.
 20. The method of claim 19, wherein the control logic is configured to control the multiplexer based on the most-significant bit (MSB) to least significant bit (LSB) range. 